-- apply_prop
-- create by panyl
-- 卷轴带来一条附加属性
--     buff(prop_id, attrib, value,round)：第一个参数为prop_id、第二个参数为prop的作用类别、第三个是属性值，第四个参数为回合数（如果没有默认为一直起效）
-- 附加属性都记录在目标的prop/buff字段下，战斗开始或结束时将被删除，每回合开始时处理一遍(过期的删掉)


return {
    apply = function(source, target, skillId, round, para, extra)
        local effectRound = - 1;

        extra = extra or {};
        local lastRound = extra.lastRound;

        if type(lastRound) == "number" then
            effectRound = round + lastRound+1;
        elseif para[4] > 0 then
            -- 不包括本回合
            effectRound = round + para[4]+1;
        end

        local prop = PropM.combine(source, "magic_last", skillId);
        effectRound = PropM.apply(prop, effectRound);
        prop = PropM.combine(source, "magic_last", "assist");
        effectRound = PropM.apply(prop, effectRound);

        -- 所有技能持续时间+
        prop = PropM.combine(source, "magic_last", "all");
        effectRound = PropM.apply(prop, effectRound);

        local v = para[3];
        -- 计算魔法效果加成
        local addon_rate = SkillM.calcMagicEffectAddon(source, skillId, true);

        v = math.modf(v * (addon_rate + 1000)/1000);

        local prop = { para[1], para[2], v, effectRound, };

        -- 增加命中动作
        SkillM.getSequence(target):hit(source, target, skillId);

        -- 记录此属性，每回合的时候需要整理下
        PropM.record(target, prop, "skill_prop");

        -- 作用目标
        return { target, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return { tonumber(arr[1]), arr[2], tonumber(arr[3]), tonumber(arr[4] or -1), };
    end,

    -- 解析技能描述
    parseDesc = function(source, skillId, desc, para)
        -- 效果
        local vbase = para[3];
        -- 计算魔法效果加成
        local addon_rate = SkillM.calcMagicEffectAddon(source, skillId, false);

        local vforce = math.modf(vbase * (addon_rate + 1000)/1000);
        local vaddon = vforce - vbase;
        if PropM.getRow(para[1])["type"] == PROP_TYPE_RATIO then
            vforce = math.modf(vforce / 10);
            vbase = math.modf(vbase / 10);
            vaddon = math.modf(vaddon / 10);
        end

        if vaddon == 0 then
            desc = string.gsub(desc, "{buff}", vforce);
        else
            desc = string.gsub(desc, "{buff}", vbase .. "(+" .. vaddon .. ")");
        end

        -- 回合数的显示
        local baseRound = para[4];
        local round = para[4];
        -- 增加持续时间的效果
        local prop = PropM.combine(source, "magic_last", skillId);
        round = PropM.apply(prop, round);
        prop = PropM.combine(source, "magic_last", "assist");
        round = PropM.apply(prop, round);
        prop = PropM.combine(source, "magic_last", "all");
        round = PropM.apply(prop, round);

        local addonRound = round - baseRound;
        if addonRound == 0 then
            desc = string.gsub(desc, "{round}", baseRound);
        else
            desc = string.gsub(desc, "{round}", baseRound .. "(+" .. addonRound .. ")");
        end

        return desc;
    end,
};
